package weaver.interfaces.zhlx.duss.action.financemodule.t6;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.zhlx.duss.utils.T6Util;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2023-11-27
 * @Description: 一般用款申请付款申请节点提交后调用接口推送资金系统验证资金计划是否超额
 * @ModifyLog:
 **/
public class WeaYbyksqlcCheckAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String src = requestInfo.getRequestManager().getSrc();
        writeLog(">>>>>WeaYbyksqlcCheckAction>>>>>requestid=" + requestid);
        try {
            String message = "调用资金系统接口返回:";
            RecordSet rs = new RecordSet();
            rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            rs.executeQuery("select * from " + tablename + "_dt1 where mainid=?", mainid);
            int count = 0;
            while (rs.next()) {
                JSONObject dataJson = new JSONObject();
                String zjjhxhwb = Util.null2String(rs.getString("zjjhxhwb"));
                String bcqkjeyb = Util.null2String(rs.getString("bcqkjeyb"));
                dataJson.put("DETAIL_ID", zjjhxhwb);
                dataJson.put("B_MONEY", bcqkjeyb);
                Map<String, Object> dataMap = new HashMap<>();
                dataMap.put("jkdymc", "WeaYbyksqlcCheckAction");
                dataMap.put("lcid", requestid);
                dataMap.put("dylc", requestid);
                dataMap.put("cz", src);
                writeLog(">>>>>WeaYbyksqlcCheckAction>>>>>dataJson=" + dataJson);
                JSONObject resultJson = T6Util.queryFundingPlan(dataJson, dataMap);
                writeLog(">>>>>WeaYbyksqlcCheckAction>>>>>resultJson=" + resultJson);
                String code = Util.null2String(resultJson.getString("code"));
                if ("success".equals(code)) {
                    JSONObject retrunData = JSONObject.parseObject(resultJson.getString("data"));
                    String code1 = Util.null2String(retrunData.getString("CODE"));
                    String msg = Util.null2String(retrunData.getString("MSG"));
                    if (!"2".equals(code1)) {
                        message += msg + ";";
                        count++;
                    }
                } else {
                    message += Util.null2String(resultJson.getString("message"));
                    count++;
                }
            }
            if (count > 0) {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            writeLog(">>>>>WeaYbyksqlcCheckAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}